import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 东莞呵呵
 * Date:2022-03-22
 * Time:14:17
 */
public class TestDemo {
    public static void main(String[] args) {
        int arr[]={44,3,2,65,7,8,3,1};
        int min=arr[0];
        int min_index=0;
        int max=arr[0];
        int max_index=0;
        int tmp=0;
        for (int i = 0; i < arr.length; i++) {
            if(arr[i]<min) {
                min=arr[i];
                min_index=i;
            }
            if(arr[i]>max){
                max=arr[i];
                max_index=i;
            }
        }
        tmp=arr[0];
        arr[0]=arr[min_index];
        arr[min_index]=tmp;

        tmp=arr[arr.length - 1];
        arr[arr.length - 1]=arr[max_index];
        arr[max_index]=tmp;

        System.out.println(Arrays.toString(arr));
    }
}
